package com.hr.设计模式.单例模式;

/**
 * @author 周恒哲
 * @date 2020/06/17
 * 懒汉式
 **/
public class Singleton1 {
    /**
     * volatile：禁止指令重排，不保证原子性
     */
    private  static Singleton1 instance;

    private Singleton1() {
    }
    public static synchronized Singleton1 getSingleton() {
        if (instance==null) {
            instance=new Singleton1();
        }
        return instance;
    }
}
